package com.ruoyi.eqmonitor.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.eqmonitor.domain.TzProblem;
import com.ruoyi.eqmonitor.service.ITzproblemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 巡河问题记录
 * @author ruoyi
 * @date 2023-06-25
 */
@RestController
@RequestMapping("/tzproblem")
public class TzproblemController extends BaseController{
    
    @Autowired
    private ITzproblemService tzproblemService;

    @GetMapping("/list")
    public TableDataInfo<?> list(TzProblem tzproblem){
        startPage();
        List<TzProblem> list = tzproblemService.selectTzproblemList(tzproblem);
        return getDataTable(list);
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id){
        return AjaxResult.success(tzproblemService.selectTzproblemByDbid(id));
    }

    @Log(title = "巡河问题记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TzProblem tzproblem){
        return toAjax(tzproblemService.save(tzproblem));
    }



    @PutMapping
    public AjaxResult edit(@RequestBody TzProblem tzproblem){
        return toAjax(tzproblemService.updateById(tzproblem));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "巡河问题记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dbids}")
    public AjaxResult remove(@PathVariable Long[] dbids){
        return toAjax(tzproblemService.removeByIds(Arrays.asList(dbids)));
    }
    
    /**
     * 导出巡河问题记录列表
     */
    @Log(title = "巡河问题记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TzProblem tzproblem){
        List<TzProblem> list = tzproblemService.selectTzproblemList(tzproblem);
        ExcelUtil<TzProblem> util = new ExcelUtil<TzProblem>(TzProblem.class);
        util.exportExcel(response, list, "巡河问题记录数据");
    }
    
}
